package customerEnter.Frame.redis.Major;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import net.sf.json.JSONArray;

import org.springframework.data.redis.core.RedisTemplate;

import customerEnter.Frame.JDBCDao.EasyBuyDB;

/**
 * redis 服務測試
 * 
 * 类名称：RedisClient 类描述： 创建人：dy 创建时间：2016-8-15 上午11:24:04
 * 
 */
public class RedisClient {

	private static RedisTemplate<String, String>	redisTemplate	= EasyBuyDB.getRedisTemplate();

	public static void main(String[] args) {

	}

	public static void TestSetData(List<?> list, String key) {
		JSONArray jsonArray2 = new JSONArray();
		jsonArray2 = JSONArray.fromObject(list);
		getRedisTemplate().opsForValue().set(key, jsonArray2.toString());

	}

	public static void TestSetTime(String key, int time, TimeUnit timeUnit) {
		getRedisTemplate().expire(key, time, timeUnit);
	}

	public static RedisTemplate<String, String> getRedisTemplate() {
		return redisTemplate;
	}

	/**
	 * 向文件中追加值
	 */
	public static void appendFileData(String content) {
		File file = new File("D:\\Workpace\\yez_easyBuyMall_frame\\src\\main\\resources\\RedisUserData");
		System.out.println("追加前文件長度：" + file.length());
		FileWriter fw;
		try {
			fw = new FileWriter(file, true);
			fw.write(content);
			fw.close();
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
		System.out.println("現有文件長度：" + file.length());
	}

}
